package src.first;

import java.lang.reflect.Method;

public class MoreMethodTest {
    public static void main(String[] args) {
        MoreMethod method = new MoreMethod();
        Class<? extends MoreMethod> aClass = method.getClass();
        Method[] methods = aClass.getMethods();
        for (int i = 0; i < methods.length; i++) {
            Method method1 = methods[i];
            System.out.println("方法的名称："+method1.getName());
            System.out.println("是否允许带可变数量的参数："+method1.isVarArgs());
            System.out.println("入口参数类型依次为：");
            Class<?>[] parameterTypes = method1.getParameterTypes();
            for (Class<?> parameterType : parameterTypes) {
                System.out.print(parameterType.getName()+",");
            }
            System.out.println();
            System.out.println("返回值类型："+method1.getReturnType());
            Class<?>[] exceptionTypes = method1.getExceptionTypes();
            for (Class<?> exceptionType : exceptionTypes) {
                System.out.print("可能抛出的异常："+exceptionType.getName());
            }
            boolean isTurn = true;
            int modifiers = method1.getModifiers();
            System.out.println("权限"+modifiers);
//            while (isTurn){
//                System.out.println("权限"+modifiers);
//                try{
//                    isTurn = false;
//                    if(modifiers == 0){
//                        method1.invoke(method);
//                    } else if (modifiers == 1) {
//                        System.out.println("返回值为："+method1.invoke(method,5));
//                    } else if (modifiers == 2) {
//                        System.out.println("返回值为："+method1.invoke(method,"7",5));
//                    }
//                    else {
//                        Object[] objects = new Object[]{new String[]{"M","N","Q","W"}};
//                        System.out.println("返回值为："+method1.invoke(method,objects));
//                     }
//                }catch (Exception e){
//                    e.printStackTrace();
//                    method1.setAccessible(true);
//                    isTurn=true;
//                }
//            }
        }
    }
}
